<?php   // $Id: bon_add_article.php 255 2008-08-07 07:14:14Z pcoustillas $ ?>
<?php
/*
Copyright (C) 2003-2004 Guy Hendrickx
Licensed under the terms of the GNU  General Public License:http://www.opensource.org/licenses/gpl-license.php
File Authors:Guy Hendrickx 
Modificication : Pierre Coustillas.
*/
require_once("include/verif.php");
require_once("include/config/common.php");
//require_once("include/language/$lang.php");
//require_once("include/utils.php");
$article=isset($_POST['article'])?$_POST['article']:"";
//$nom=isset($_POST['nom'])?$_POST['nom']:"";
$num_bon=isset($_POST['num_bon'])?$_POST['num_bon']:"";
$quanti=isset($_POST['quanti'])?$_POST['quanti']:"";
$num_lot=isset($_POST['lot'])?$_POST['lot']:"";

//on recupere le prix htva
$sql2 = "SELECT * FROM ${tblpref}article WHERE num = $article";
$result = mysql_query($sql2) or die("Erreur selection du prix ht de l'article !<br/>$sql2<br/>" . mysql_error());
$data=mysql_fetch_array($result);
$prix_article = $data['prix_htva'];
$taux_tva = $data['taux_tva'];


$total_htva = $prix_article * $quanti ;
$mont_tva = $total_htva / 100 * $taux_tva ;
//inserer les données dans la table du contenu des bons.

//mysql_select_db($db) or die ("Could not select $db database");
$sql1 = "INSERT INTO ${tblpref}cont_bon(num_lot, quanti, article_num, bon_num, tot_art_htva, to_tva_art) 
		VALUES ('$num_lot', '$quanti', '$article', '$num_bon', '$total_htva', '$mont_tva')";
mysql_query($sql1) or die("Erreur creation de l'article !<br/>$sql1<br>" . mysql_error());

//apres le traitement on recharge la page qui affiche le bon
header("Location: bon_edit.php?num_bon=$num_bon");

?>